#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;

class Solution{
    private:
    
    public:
    int ans1(int k, int w, vector<int>& profits, vector<int>& capital){
        priority_queue<int, vector<int>, less<int>> maxHeap;
        int len = capital.size();
        vector<pair<int, int>> arr;
        for(int i = 0; i != len; i++){
            arr.push_back({capital[i], profits[i]});
        }
        sort(arr.begin(), arr.end());
        int p = 0;
        for(int i = 0; i != k; i++){
            while(p < len && arr[p].first <= w){
                maxHeap.push(arr[p].second);
                p++;
            }
            if(!maxHeap.empty()){
                w = w + maxHeap.top();
                maxHeap.pop();
            }else{
                break;
            }
        }

        return w;
    }
};

void test(){
    Solution s;
    int k = 2, w = 0;
    vector<int> profits = {3,1,2}, capital = {1,0,2};

    int ret = s.ans1(k, w, profits, capital);
    cout << ret << endl;
}

int main(void){
    test();

    return 0;
}